<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2020-06-30
  Time: 14:37
  To change this template use File | Settings | File Templates.
--%>
<%@ page language="java" contentType="text/html; charset=utf-8" %>
<%@page import="java.lang.*" %>
<%@ page import="entity.Movie" %>
<%@ page import="java.util.List" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="test.selectMovies" %>
<%@ page import="java.io.PrintWriter" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
    <base href="<%=basePath%>">
    <title>电影信息页面</title>
    <link rel="stylesheet" href="css/mainStyle.css" type="text/css" media="all">
</head>

<body>
<%
    selectMovies sm = new selectMovies();
    List<Movie> list = sm.selectAll();
    System.out.println("--movieList---" + list.isEmpty());
    if (list.isEmpty()) {
%>
<script language='javascript'>
    alert('没有数据！');
</script>
<%
    }
%>
<ul>
    <li><a class="active" href="index.jsp">电影列表</a></li>
    <li><a href="scoreBar.jsp" target="_blank">电影平均分</a></li>
    <li><a href="javascript:openUploadFile();">上传rating</a></li>
</ul>
<%--背景半透明--%>
<div id="hidebg" class="hidebg">
</div>
<%--弹出框--%>
<form action="<%=path %>/UploadServlet" method="post" class="uploadForm" id="uploadForm"
      enctype="multipart/form-data">
    <h3>请上传rating文件</h3>
    <input class="" type="file" name="SendFilePath"
           onchange="document.getElementById('FilePath').value=this.value"/>
    <input type="hidden" name="ratingfile" id="FilePath" value=""/>
    <input type="submit" value="确定" onclick="return check();" class="uploadbtn"/>
    <input type="button" value="退出" class="uploadbtn" onclick="closeUpload();"/>
</form>

<script>
    function openUploadFile() {
        document.getElementById("hidebg").style.display = "block";
        document.getElementById("hidebg").style.height = document.body.clientHeight + "px";
        document.getElementById("uploadForm").style.display = "block";
    }

    function closeUpload() {
        document.getElementById("hidebg").style.display = "none";
        document.getElementById("uploadForm").style.display = "none";
    }

    function check() {
        if (uploadForm.SendFilePath.value.length == 0) {
            alert("请选择文件！");
            uploadForm.SendFilePath.focus();
            return false;
        }
        document.getElementById("uploadForm").style.display = "none";
        document.getElementById("hidebg").style.display = "none";
        return true;
    }

</script>

<div class="container">
    <!-- 查询按钮 -->
    <div class="Search">
        <form action="MoviesServlet" method="post">
            <div class="formStyle">
                <div class="con">
                <span class="radio_box"><input type="radio" id="radio_1" name="type" value="1" checked=""><label
                        for="radio_1"></label><em style="font-style: normal">前匹配</em></span>
                    <span class="radio_box"><input type="radio" id="radio_2" name="type" value="2"><label
                            for="radio_2"></label><em style="font-style: normal">后匹配</em></span>
                    <span class="radio_box"><input type="radio" id="radio_3" name="type" value="3"><label
                            for="radio_3"></label><em style="font-style: normal">模糊过滤</em></span>
                </div>
                <div class="flex">
                    <input type="text" name="movieName" id="movieName" placeholder="请输入电影关键字" required
                           maxLength="20">
                    <input type="submit" value="查询电影" class="Search_Button">
                </div>
            </div>
        </form>
    </div>
    <!-- 所有电影信息表: -->
    <div class="StaffInfo_All">
        <%
            if (!list.isEmpty()) {
        %>
        <table border="1">
            <tr>
                <td>电影编号</td>
                <td>电影片名</td>
                <td>电影类型</td>
                <td>实时评分</td>
            </tr>
            <%
                for (int i = 0; i < list.size(); i++) {
            %>
            <tr>
                <td><%=list.get(i).getMovieId()%>
                </td>
                <td><%=list.get(i).getTitle()%>
                </td>
                <td><%=list.get(i).getGenres()%>
                </td>
                <td style="text-align: center;">
                    <a href="dynamicRating.jsp?movieID=<%=list.get(i).getMovieId()%>">
                        <img src="../images/rat.jpg" style="width: 25px;height: 25px;"/>
                    </a>
                </td>
            </tr>
            <%
                }
            %>
        </table>
        <%
        } else {
        %>
        <h3>没有查到数据!</h3>
        <%
            }
        %>
    </div>
</div>
</body>
</html>
